package cn.bdqn.t354.controller;

import cn.bdqn.t354.pojo.Product;
import cn.bdqn.t354.service.ProductService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
@RequestMapping("/product")
public class ProductController {
    @Resource
    private ProductService productService;

    /**
     * 列表展示
     *
     * @param prodName
     * @param prodType
     * @param prodBatch
     * @param pageIndex
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(String prodName, String prodType, String prodBatch,
                       @RequestParam(defaultValue = "1") Integer pageIndex,
                       Model model) {
        //设置每页显示条数
        int pageSize = 3;

        //查询每页显示的数据
        IPage<Product> productPager =
                productService.getProductsByPage(prodName, prodType, prodBatch, pageIndex, pageSize);
        model.addAttribute("productPager", productPager);

        //查询条件回显
        model.addAttribute("prodName", prodName);
        model.addAttribute("prodType", prodType);
        model.addAttribute("prodBatch", prodBatch);

        return "product/list";
    }
}
